class AddDefaultRolesAndUsers < ActiveRecord::Migration
  def self.up

    roles = [
              {:title => 'admin', :name => 'Администратор'}, 
              {:title => 'moderator', :name => 'Модератор'}
            ]
            
    for role in roles do
      @role = Role.new(:title => role[:title], :name => role[:name])
      @role.save
    end
    
    user = User.new(:login => 'test', :email => 'test@test.ru', :password => 'testtest', :password_confirmation => 'testtest')
    user.roles << Role.find_by_title('admin')
    user.save!
    user.activate!

  end

  def self.down
    User.find_by_login('test').destroy
    Roles.all.destroy
  end
end
